//
//  RootViewController.m
//  Youhuiju
//
//  Created by yutenys on 16/7/13.
//  Copyright © 2016年 yutenys. All rights reserved.
//

#import "RootTabBarController.h"
#import "YHJHomeViewController.h"
#import "YHJShopCarViewController.h"
#import "YHJMyCenterViewController.h"

@interface RootTabBarController ()<UITabBarControllerDelegate>

@property (nonatomic ,strong) UINavigationController *homeNavigationController;
@property (nonatomic ,strong) UINavigationController *shopCarNavigationController;
@property (nonatomic ,strong) UINavigationController *myCenterNavigationController;

@end

@implementation RootTabBarController

- (void)dealloc {
}

- (void)viewDidLoad {
    [super viewDidLoad];
    
    self.shouldSelectItem = YES;
    
    self.delegate = self;
    
    [self p_initialViewController];
}

#pragma mark - Private Method

- (void)p_initialViewController {
    
    //修改点击时tabbar字体大小
   // [[UITabBarItem appearance] setTitleTextAttributes:@{ UITextAttributeTextColor : [UIColor colorWithHexString:@"ff5f7d"],UITextAttributeFont:[UIFont systemFontOfSize:11 * FitH]}            forState:UIControlStateHighlighted];

    
    //修改未点击时tabbar字体大小
   // [[UITabBarItem appearance] setTitleTextAttributes:@{ UITextAttributeTextColor : [UIColor colorWithHexString:@"666666"],UITextAttributeFont:[UIFont systemFontOfSize:11 * FitH]}            forState:UIControlStateNormal];
    
    //修改tabbar字体位置
    [[UITabBarItem appearance] setTitlePositionAdjustment:UIOffsetMake(-3, -3)];
    
    YHJHomeViewController *homeViewController = [[YHJHomeViewController alloc] init];
    UITabBarItem *homePage = [[UITabBarItem alloc] initWithTitle:@"首页" image:[LoadImage(@"homePage.png") imageWithRenderingMode:UIImageRenderingModeAlwaysOriginal] selectedImage:[LoadImage(@"homePage1.png") imageWithRenderingMode:UIImageRenderingModeAlwaysOriginal]];
    
    
    homeViewController.tabBarItem = homePage;
    [homeViewController.tabBarItem setTitleTextAttributes:@{UITextAttributeTextColor : [UIColor colorWithHexString:@"ff9a64"]} forState:UIControlStateSelected];
    
    self.homeNavigationController = [[UINavigationController alloc] initWithRootViewController:homeViewController];
    
    
    YHJShopCarViewController *shopCarViewController = [[YHJShopCarViewController alloc] init];
    //    SellingViewController *sellingViewController = [[UIViewController alloc]init];
    UITabBarItem *shopCar = [[UITabBarItem alloc] initWithTitle:@"购物车" image:[LoadImage(@"shopCar.png") imageWithRenderingMode:UIImageRenderingModeAlwaysOriginal] selectedImage:[LoadImage(@"shopCar1.png") imageWithRenderingMode:UIImageRenderingModeAlwaysOriginal]];
    shopCarViewController.tabBarItem = shopCar;
     [shopCarViewController.tabBarItem setTitleTextAttributes:@{UITextAttributeTextColor : [UIColor colorWithHexString:@"ff9a64"]} forState:UIControlStateSelected];
    
    self.shopCarNavigationController = [[UINavigationController alloc] initWithRootViewController:shopCarViewController];
    
    YHJMyCenterViewController *myCenterViewController = [[YHJMyCenterViewController alloc] init];
    UITabBarItem *myCenter = [[UITabBarItem alloc] initWithTitle:@"个人中心" image:[LoadImage(@"myCenter.png") imageWithRenderingMode:UIImageRenderingModeAlwaysOriginal] selectedImage:[LoadImage(@"myCenter1.png") imageWithRenderingMode:UIImageRenderingModeAlwaysOriginal]];
    
    myCenterViewController.tabBarItem = myCenter;
     [myCenterViewController.tabBarItem setTitleTextAttributes:@{UITextAttributeTextColor : [UIColor colorWithHexString:@"ff9a64"]} forState:UIControlStateSelected];
    self.myCenterNavigationController = [[UINavigationController alloc] initWithRootViewController:myCenterViewController];
    
    self.tabBar.tintColor = [UIColor blackColor];
    
    [self setViewControllers:@[
                               self.homeNavigationController,
                               self.shopCarNavigationController,
                               self.myCenterNavigationController
                               ]];
    
    
  
    
    
//    UITabBarItem *item1 = self.tabBar.items[0];
//     [item1 setImageInsets:UIEdgeInsetsMake(0, 0, 0, 0)];
//    [self tabbarItem:item1
//           imageName:@"homePage.png"
//     selectImageName:@"homePage1.png"];
//    
//    UITabBarItem *item2 = self.tabBar.items[1];
//    [self tabbarItem:item2
//           imageName:@"tabbar_check_normal"
//     selectImageName:@"tabbar_check_selected"];
//    
//    UITabBarItem *item3 = self.tabBar.items[2];
//    [self tabbarItem:item3
//           imageName:@"tabbar_more_normal"
//     selectImageName:@"tabbar_more_selected"];
    
}





//- (void)tabbarItem:(UITabBarItem *)item
//         imageName:(NSString *)imageName
//   selectImageName:(NSString *)selectImageName {
//    UIImage *image = [UIImage imageNamed:imageName];
//    image = [image imageWithRenderingMode:UIImageRenderingModeAlwaysOriginal];
//    item.image = image;
//    UIImage *selectImage = [UIImage imageNamed:selectImageName];
//    selectImage = [selectImage imageWithRenderingMode:UIImageRenderingModeAlwaysOriginal];
//    item.selectedImage = selectImage;
//}


#pragma mark - UITabBarDelegate

- (BOOL)tabBarController:(UITabBarController *)tabBarController shouldSelectViewController:(UIViewController *)viewController {
    
    return self.shouldSelectItem;
}


@end
